package com.weather.service;

import com.weather.service.InsertSql;
import net.sf.json.JSONObject;


public class RequestWeather {
	//public static final String GET_URL = "http://m.weather.com.cn/data/101010100.html";
	//public static final String GET_URL="http://www.weather.com.cn/data/sk/101010100.html";
	//public static final String GET_URL="http://tianqi.cncn.com/beijing";
	//public static final String GET_URL ="http://www.weather.com.cn/data/cityinfo/101010100.html";
	//http://weather.china.com.cn/forecast/2-1-1.html
	public static final String GET_URL="http://weather.51wnl.com/weatherinfo/GetMoreWeather?cityCode=101010100&weatherType=0";
	
	static String lines; 
	 public static void RequestWeatherWeek() throws Exception{

			String jsonstr = RequestURL.RequestWeathers(GET_URL);
			
			JSONObject json = JSONObject.fromObject(jsonstr);
			JSONObject jsonob=JSONObject.fromObject(json.getString("weatherinfo"));
			System.out.println(jsonstr);
			String week = jsonob.getString("date_y").replaceAll("[^0-9]","-");
			week=week.substring(0, week.length()-1);
            String sql = "insert into bj_future_weather VALUES ("	
            		+"'"+week.toString()+"'"+","
            		+"'"+jsonob.getString("city")+"'"+","
            		+"'"+jsonob.getString("temp1")+"'"+","
            		+"'"+jsonob.getString("temp2")+"'"+","
            		+"'"+jsonob.getString("temp3")+"'"+","
            		+"'"+jsonob.getString("temp4")+"'"+","
            		+"'"+jsonob.getString("temp5")+"'"+","
            		+"'"+jsonob.getString("temp6")+"'"+","
            		+"'"+jsonob.getString("weather1")+"'"+","
            		+"'"+jsonob.getString("weather2")+"'"+","
            		+"'"+jsonob.getString("weather3")+"'"+","
            		+"'"+jsonob.getString("weather4")+"'"+","
            		+"'"+jsonob.getString("weather5")+"'"+","
            		+"'"+jsonob.getString("weather6")+"'"+")";
            System.out.println(sql);
            int isok = InsertSql.insertable(sql);
            if (isok==1){
            	System.out.println("success");
           
            }else if (isok==500){
            	System.out.println("PRIMARY");
            }else{
            	System.out.println("fail");
            }
	 }
	 public static void main(String[] args) throws Exception {
		 RequestWeatherWeek();

		}

}
